package com.ebupt.service

import androidx.annotation.Keep
import androidx.lifecycle.LiveData
import androidx.paging.DataSource
import androidx.paging.PagingData
import androidx.paging.PagingSource
import androidx.room.*

@Keep
@Entity(tableName = "userinfo")
class AppUserInfo {
    @PrimaryKey(autoGenerate = true)
    var id:Long = 0
    var userType:String = "普通客户"
    @Embedded
    var user: User? = null


    override fun toString(): String {
        return "AppUserInfo(id=$id, userType='$userType', user=${user.toString()})"
    }


}
@Keep
class User{
    @ColumnInfo(name = "userid")
    var id:Long = 0
    var userName = ""
    var userAge = 0


    override fun toString(): String {
        return "User(id=$id, userName='$userName', userAge=$userAge)"
    }


}




@Dao
interface UserDao{

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUser(user: AppUserInfo)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertUserList(userList:List<AppUserInfo>)

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun updateUser(user: AppUserInfo)

    @Delete
    fun delete(user: AppUserInfo)

    @Query("select*from userinfo where id = :id")
    fun getUserById(id:Long): LiveData<AppUserInfo>

    @Query("select * from userinfo")
    fun getAllUser():LiveData<List<AppUserInfo>>



    @Query("select * from userinfo")
    fun getAllUserNomal():List<AppUserInfo>


   /* @Query("select*from userinfo")
    fun getAllUserForPaging(): PagingData<AppUserInfo>*/


}